package com.example.interactactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.lang.String;

public class SecondActivity extends AppCompatActivity {

    private TextView msg;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        btn = (Button) findViewById(R.id.feedbackBtn);
        msg = (TextView) findViewById(R.id.receiveMsg);

        Intent intent = getIntent();

        //msg.setText(intent.getIntExtra("num",0) +":"+ intent.getStringExtra("msg"));
        msg.append(intent.getIntExtra("num",0)+":"+intent.getStringExtra("msg"));

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SecondActivity.this,MainActivity.class);
                //intent.putExtra("msg", "I'm fine, thank you!");
                intent.putExtra("msg1","小明：我很好");//把返回数据存入Intent
                msg.append(intent.getIntExtra("num",1)+":"+intent.getStringExtra("msg1"));
                setResult(RESULT_OK, intent);//设置返回数据ReSULT_OK为默认值
                finish();//关闭Activity

            }
        });

    }
}
